let vue = new Vue({
    el: '.main-content',
    data:function () {
        return {
            result: {},
            officeName:'',
            setting: {
                data: {//设置树的数据的配置
                    simpleData: {//简单数据格式配置  一维结构节点数组 不设置默认是多维结构数组
                        enable: true,  //开启使用简单数据格式
                        // idKey: 'id', //设置节点中的id属性key  默认
                        pIdKey: 'parentId' //设置父节点id属性key   与数据库中的字段需要对应
                    }
                },
                callback: {
                    onClick: this.onClick2
                },
                view: {//显示设置
                    //当显示某个节点/更新节点的时候，自动会调用字体设置
                    fontCss: this.fontCss1
                }
            },
            nodes: []
        }
    },
            methods: {
                initTree:function () {
                    axios({
                        url:'office/select'
                    }).then(response=>{
                        this.nodes=response.data.obj;
                        //动态生成父节点 全部
                        this.nodes[this.nodes.length] = {id:0,name:'机构列表'};
                        //初始化树(dom节点对象,配置对象,节点数组)
                        let zTreeObj = $.fn.zTree.init($('#treeMenu'),this.setting,this.nodes);
                        zTreeObj.expandAll(true);
                        let nodes = zTreeObj.getNodes();//获取组装后的节点数组
                    }).catch(error=>{
                        layer.msg(error.message)
                    })
                },
                onClick2:function (event, treeId, treeNode) {
                    if (treeNode.id===0){
                        return;
                    }
                    this.officeName=treeNode.name;
                    // $("#opneOrClose").removeClass('open')
                },
                selectByName: function (pageNum, pageSize) {
                    axios({
                        url: `office/selectByName/${pageNum}/${pageSize}`,
                        params:{officeName: this.officeName}
                    }).then(rs => {
                        this.result = rs.data.obj;
                    })
                },
                select: function (pageNum, pageSize) {
                    axios({
                        url: `office/select/${pageNum}/${pageSize}`,
                    }).then(rs => {
                        this.result = rs.data.obj;
                    })
                },
                detailView: function (o) {
                    layer.office=o;
                    layer.message = '';
                    layer.open({
                        type: 2,
                        title: false,
                        area: ['80%', '80%'],
                        content: 'office/detail',
                        end:()=>{
                        }
                    })
                },
                update: function (o) {
                    layer.office=o;
                    layer.message = '';
                    layer.open({
                        type: 2,
                        title: false,
                        area: ['80%', '80%'],
                        content: 'office/update',
                        end:()=>{
                            layer.msg(layer.message);
                            this.selectAll(1,5)
                        }
                    })
                },
                deleteOffice:function (o) {
                    axios({
                        url:'office/deleteOffice',
                        method:'put',
                        data:o
                    }).then(rs=>{
                        if(rs.data.success){
                            layer.msg(rs.data.msg);
                            this.select(1,5);
                            this.initTree()
                        }
                    })
                }
        }
    ,
    created: function () {
        this.select(1,5);
        this.initTree()
    }
});